package com.fm.demo.splash

import android.animation.*
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import com.fm.common.base.BaseBActivity
import com.fm.demo.MainActivity
import com.fm.demo.databinding.ActivitySplashBinding

class SplashActivity : BaseBActivity<ActivitySplashBinding>() {

    @SuppressLint("Recycle")
    override fun initView(savedInstanceState: Bundle?) {
        val scaleXAnimation = ObjectAnimator.ofFloat(binding.splashIvIcon, "scaleX", 1f, 1.5f, 1f, 0.8f, 0.8f, 1f)
        val scaleYAnimation = ObjectAnimator.ofFloat(binding.splashIvIcon, "scaleY", 1f, 1.5f, 1f, 0.8f, 0.8f, 1f)
        AnimatorSet().let {
            it.play(scaleXAnimation).with(scaleYAnimation)
            it.duration = 1200
            it.addListener(object : Animator.AnimatorListener {
                override fun onAnimationStart(animation: Animator?) {
                }

                override fun onAnimationEnd(animation: Animator?) {
                    startActivity(Intent(this@SplashActivity, MainActivity::class.java))
                    finish()
                }

                override fun onAnimationCancel(animation: Animator?) {
                }

                override fun onAnimationRepeat(animation: Animator?) {
                }

            })
            it.start()
        }
    }
}
